from flask import Flask,g,session

app = Flask(__name__)

# app.config['SECRET_KEY'] = 'skidhfikshighsd'
app.secret_key = 'sjfdjkfsjfjsk'

@app.route('/login/')
def login():
    print('运行代码 222222222')
    print('Hello!!!!')
    session['uname'] = '吕布'
    return f'Hello'

@app.route('/home/')
def home():
    print('运行代码 3333333333')
    if hasattr(g, 'uname'):
        return f'用户已登录！用户名是：{g.uname}'
    return '用户没有登录！'

@app.before_request
def before_request():
    print('运行代码 111111111111')
    uname = session.get('uname')
    if uname:
        g.uname = uname
    print('这个是每次请求时，需要执行的逻辑！！！')


if __name__ == '__main__':
    app.run(debug=True)